<template>
    <div class="flutter-navigation-container">
        <h1 class="page-title">Flutter社区</h1>

        <!-- 官网分类 -->
        <h2 class="category-title">官网下载</h2>
        <div class="cards-container">
            <div v-for="site in officialSites" :key="site.id" class="card" @click="goToSite(site.url)">
                <img :src="site.image" :alt="site.title" class="card-image" />
                <div class="card-content">
                    <h3 class="card-title">{{ site.title }}</h3>
                    <p class="card-description">{{ site.description }}</p>
                </div>
            </div>
        </div>

        <!-- 博客分类 -->
        <h2 class="category-title">实用网站</h2>
        <div class="cards-container">
            <div v-for="site in bookSites" :key="site.id" class="card" @click="goToSite(site.url)">
                <img :src="site.image" :alt="site.title" class="card-image" />
                <div class="card-content">
                    <h3 class="card-title">{{ site.title }}</h3>
                    <p class="card-description">{{ site.description }}</p>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import { resourceSite } from './data/netResource'
export default {
    name: 'FlutterNavigation',
    data() {
        return {
            sites: resourceSite
        }
    },
    computed: {
        officialSites() {
            return this.sites.filter(site => site.category === 'codeTool');
        },
        bookSites() {
            return this.sites.filter(site => site.category === 'practicalNet');
        }
    },
    methods: {
        goToSite(url: string, route?: string) {
            if (route) {
                this.$router.push(route);
            } else if (url) {
                window.open(url, '_blank');
            }

        }
    }
}
</script>

<style scoped>
.flutter-navigation-container {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.page-title {
    text-align: center;
    margin-bottom: 30px;
    color: #333;
}

.category-title {
    font-size: 24px;
    margin: 30px 0 15px 0;
    color: #333;
    border-left: 4px solid #007bff;
    padding-left: 10px;
}

.cards-container {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 20px;
}

.card {
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    background-color: #fff;
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
}

.card-image {
    width: 100%;
    height: 120px;
    object-fit: contain;
    padding: 15px;
    background-color: #828282;
}

.card-content {
    padding: 15px;
}

.card-title {
    font-size: 16px;
    margin: 0 0 8px 0;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-description {
    font-size: 12px;
    color: #666;
    margin: 0;
    line-height: 1.4;
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 1200px) {
    .cards-container {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (max-width: 992px) {
    .cards-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .cards-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 576px) {
    .cards-container {
        grid-template-columns: 1fr;
    }
}
</style>